<?php /*
	*/ ?>
<? 
include("system/config.inc.php");

// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:adminlogin.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
				
				$txtcountry = $_REQUEST['txtcountry'];
				$txtisocode2 = $_REQUEST['txtisocode2'];
				$txtisocode3 = $_REQUEST['txtisocode3'];		
				
				$insert="INSERT INTO `tblcountry` ( `varcountryname` , `char_iso-code2` , `char_iso-code3`) 
				VALUES ('$txtcountry', '$txtisocode2', '$txtisocode3')";
				
				$sql=$obj_db->insert($insert);
								
				header("location:country.php?msg=add");
				die();
	}	
		

// UPDATE the record
$txtcountry1 = "";
$txtisocode21 = "";
$txtisocode31 = "";

$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tblcountry where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$txtcountry1 = $row['varcountryname'];	   
		   		$txtisocode21 = $row['char_iso-code2'];
				$txtisocode31 = $row['char_iso-code3'];
				
				
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Edit")
		{
				$txtcountry = $_REQUEST['txtcountry'];
				$txtisocode2 = $_REQUEST['txtisocode2'];
				$txtisocode3 = $_REQUEST['txtisocode3'];
			
			$sql_upd ="UPDATE tblcountry SET  
						`varcountryname` = '$txtcountry',
						`char_iso-code2` = '$txtisocode2',						 
						`char_iso-code3` = '$txtisocode3'
						where intid ='$screen_id'";
						 
			//echo $sql_upd;
			//die();
			
			$result = $obj_db->edit($sql_upd);
			$action=1;
			
			header("location:country.php?msg=edit");
			die();
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  $_REQUEST['intid'];
		$sql= "DELETE FROM `tblcountry` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:country.php?msg=del");
		die();
	}
}


?>

<link href="css/dunt.css" rel="stylesheet" type="text/css" /><title>ibccomputers.com::Admin</title>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><? include(INC."top.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%">
	<?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addcountry' || trim($_REQUEST['script'])=='editcountry')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="manuf">
		
      <table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>Enter Zone  </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="30%" align="right" class="sltimg">*Country Name</td>
          <td width="3%">:</td>
          <td width="56%" align="left"><label>
            <input name="txtcountry" type="text" id="txtcountry" value="<?=$txtcountry1;?>" />
          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Zone Name </td>
          <td>:</td>
          <td align="left"><input name="txtisocode2" type="text" id="txtisocode2" value="<?=$txtisocode21;?>" /></td>
          <td>&nbsp;</td>
        </tr>
        

        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Edit":"Submit"; ?>" /></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table>
    <?
	}
}
else
{
?>
		<table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="3" align="left"><strong>Zones List... </strong>&nbsp;&nbsp;</td>
            <td align="center"><a href="country.php?script=addcountry" class="aa"><img src="images/new.jpg" border="0" /></a></td>
          </tr>
          <tr class="tblbg3">
            <td align="center"><strong>Country </strong></td>
			
            <td align="center"><strong>Zone</strong></td>          
            <td align="center"><strong>Edit</strong></td>
            <td align="center"><strong>Delete</strong></td>
          </tr>
          <?
	  
	  
	  
	  /**************************************
		PAGING CODE START
		**************************************/
		//$rowperpage=23;
		$tablename="tblcountry";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
		PAGING CODE ENDING
		**************************************/
		?>
          <?php
   		$sql="select * from tblcountry Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><? echo $result[$i]['varcountryname'];?></td>
			
            <td align="center"><? echo $result[$i]['char_iso-code2'];?></td>
            
            <td align="center"><a class="link" Title="Click here to Edit" href="country.php?script=editcountry&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="country.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <? }}?>
          <tr>
            <td colspan="4" align="center"><?
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
          </tr>
        </table>
		<? }?>
        </form>	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><? include("inc/bottom.php");?></td>
  </tr>
</table>


